<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8"/>
    <title>全选、不选、反选</title>
<script>
    window.onload = function(){
    	var oBtn1 = document.getElementById('btn1');   //选中button  1
    	var oBtn2 = document.getElementById('btn2');   //选中button  2
    	var oBtn3 = document.getElementById('btn3');   //选中button  3
    	var oDiv = document.getElementById('div1');    //选中div
        var aCh = oDiv.getElementsByTagName('input');   //选中div里的所有input
        
        //全选
        oBtn1.onclick = function(){
            for(var i=0;i<aCh.length;i++){
            	aCh[i].checked = true;   
            }
        }
        //不选
        oBtn2.onclick = function(){
            for(var i=0;i<aCh.length;i++){
            	aCh[i].checked = false;   
            }
        }
        //反选
        oBtn3.onclick = function(){
            for(var i=0;i<aCh.length;i++){
            	if(aCh[i].checked == true){
            		aCh[i].checked = false; 
            	}else{
            		aCh[i].checked = true;
            	}
            }
        }
    }
</script>
</head>
<body>
	<input id="btn1" type="button" value="全选"/>
	<input id="btn2" type="button" value="不选"/>
	<input id="btn3" type="button" value="反选"/><br>
	<div id="div1">
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
		<input type="checkbox"/><br>
    </div>
</body>
</html>

































